type Tree = {
    id?: string | number
    [key: string]: any
    children?: Tree[]
}

type FilterCb = (node: Tree, parent: Tree | undefined) => boolean
export const createTree = (data: Tree[], parent: Tree | undefined, parentFilterCb: FilterCb): Tree[] => {
    if (!data || !data.length) return []
    const topTree = data.filter(node => parentFilterCb(node, parent))
    return topTree.map((node) => {
        return {
            ...node,
            children: createTree(data, node, parentFilterCb)
        }
    })
} 